/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.yagnus.langutils.freezable;

import java.util.Collection;
import java.util.Iterator;
import java.util.ListIterator;
import org.yagnus.interfaces.Freezable;
import java.util.List;

import org.yagnus.exceptions.DisallowedOperationException;

/**
 * 
 * @author hc.busy
 */
public class FreezableList<T> extends FreezableBase implements List<T>, Freezable {

    List<T> l;

    public FreezableList(List<T> in) {
        this.l = in;
    }

    public <T> T[] toArray(T[] a) {
        return l.toArray(a);
    }

    public Object[] toArray() {
        return l.toArray();
    }

    public List<T> subList(int fromIndex, int toIndex) {
        return new FreezableList<T>(l.subList(fromIndex, toIndex));
    }

    public int size() {
        return l.size();
    }

    public T set(int index, T element) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return l.set(index, element);
    }

    public boolean retainAll(Collection<?> c) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return l.retainAll(c);
    }

    public boolean removeAll(Collection<?> c) {
        if (frozen && c.size() > 0) {
            throw new DisallowedOperationException();
        }
        return l.removeAll(c);
    }

    public T remove(int index) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return l.remove(index);
    }

    public boolean remove(Object o) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return l.remove(o);
    }

    public ListIterator<T> listIterator(int index) {
        return l.listIterator(index);
    }

    public ListIterator<T> listIterator() {
        return l.listIterator();
    }

    public int lastIndexOf(Object o) {
        return l.lastIndexOf(o);
    }

    public Iterator<T> iterator() {
        return l.iterator();
    }

    public boolean isEmpty() {
        return l.isEmpty();
    }

    public int indexOf(Object o) {
        return l.indexOf(o);
    }

    public int hashCode() {
        return l.hashCode();
    }

    public T get(int index) {
        return l.get(index);
    }

    public boolean equals(Object o) {
        return l.equals(o);
    }

    public boolean containsAll(Collection<?> c) {
        return l.containsAll(c);
    }

    public boolean contains(Object o) {
        return l.contains(o);
    }

    public void clear() {
        l.clear();
    }

    public boolean addAll(int index, Collection<? extends T> c) {
        if (frozen && c.size() > 0) {
            throw new DisallowedOperationException();
        }
        return l.addAll(index, c);
    }

    public boolean addAll(Collection<? extends T> c) {
        if (frozen && c.size() > 0) {
            throw new DisallowedOperationException();
        }
        return l.addAll(c);
    }

    public void add(int index, T element) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        l.add(index, element);
    }

    public boolean add(T e) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return l.add(e);
    }
}
